<{include file="public_html/header.html"}>
<{include file="public_html/left_menu.html"}>
<script type="text/javascript" charset="utf-8" src="/static/public/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/public/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/static/public/ueditor/lang/zh-cn/zh-cn.js"></script>

<blockquote class="layui-elem-quote"><{$action}></blockquote>

<form class="layui-form layui-form-pane" method="post" action="" id="form_add_role">
	<input type="hidden" name="id" value="<{$topic_info['id']|default:'0'}>" />

	<div class="layui-form-item">
		<label class="layui-form-label">科目</label>
		<div class="layui-input-block">
			<select name="subject_id" id="subject" lay-filter="subject" lay-verify="required" disabled>
				<option value="0">请选择科目</option>
				<{foreach from=$subject item=item}>
					<option value="<{$item.id}>" <{if $t_topic_info['subject_id']|default:"" eq $item.id}>selected="selected"<{/if}>><{$item.name}></option>
				<{/foreach}>
			</select>
		</div>
	</div>

		<div class="layui-form-item">
		<label class="layui-form-label">课本</label>
		<div class="layui-input-block">
			
			<select name="book_id" id="book" lay-filter="book" lay-verify="required" disabled>
				<option value="0">请选择课本</option>
				<{if isset($book_list) AND $book_list|count  > 0}>
				<{foreach from=$book_list item=book}>
					<option value="<{$book.id}>" <{if $book.id == $t_topic_info.book_id|default:""}> selected <{/if}>><{$book.title}></option>
				<{/foreach}>
				<{/if}>
			</select>
			<input type="hidden" id="book_name" name="book_name" />
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">章节</label>
			<div class="layui-input-block">
				<select name="chapter_id" id="chapter_id" lay-verify="required" disabled>
					<option value="0">请选择章节</option>
					<{if isset($chapter_list_data) AND $chapter_list_data|count  > 0}>
						<{foreach from=$chapter_list_data item=item}>
							<!-- <optgroup label="<{$item.title}>"> -->
							<option <{if $item.id == $t_topic_info.chapter_id}> selected <{/if}> value="<{$item.id}>"><{$item.title}></option>
							<{if $item.sub|count > 0}>
								<{foreach from=$item.sub item=item1}>
									<option <{if $item1.id == $t_topic_info.chapter_id}> selected <{/if}> value="<{$item1.id}>">----<{$item1.title}></option>
								<{/foreach}>
							<{/if}>
							<!-- </optgroup> -->
						<{/foreach}>
					<{/if}>
				</select>
			</div>
	</div>

	<{if $t_topic_info.has_sub_topic == 0}>
	<div class="layui-form-item">
		<label class="layui-form-label">题目类型</label>
		<div class="layui-input-block">
			<select name="type" lay-verify="required" lay-filter="q_type" id="q_type" <{if $t_topic_info.type|default:"" > 0}> disabled <{/if}>>
				<option value="1" <{if 1 == $t_topic_info.type|default:""}> selected <{/if}>>单选题</option>
				<option value="2" <{if 2 == $t_topic_info.type|default:""}> selected <{/if}>>多选题</option>
				<option value="3" <{if 3 == $t_topic_info.type|default:""}> selected <{/if}>>判断题</option>
				<option value="4" <{if 4 == $t_topic_info.type|default:""}> selected <{/if}>>简答题</option>
				<option value="5" <{if 5 == $t_topic_info.type|default:""}> selected <{/if}>>填空题</option>
				<option value="6" <{if 6 == $t_topic_info.type|default:""}> selected <{/if}>>计算题</option>
			</select>
		</div>
	</div>
	<{/if}>

	<div class="layui-input-block">
		<!-- 加载编辑器的容器 -->
	    <script id="container" name="subject_text" type="text/plain">
	        <{$t_topic_info.subject_text|default:""}>
	    </script>
	    <!-- 配置文件 -->
	    <script type="text/javascript" src="/static/public/ueditor/ueditor.config.js"></script>
	    <!-- 编辑器源码文件 -->
	    <script type="text/javascript" src="/static/public/ueditor/ueditor.all.js"></script>
	    <!-- 实例化编辑器 -->
	    <script type="text/javascript">
	        var ue = UE.getEditor('container');
	    </script>
	</div>

	<{if $t_topic_info.has_sub_topic == 1}>

	<div class="layui-form-item">
		<label class="layui-form-label">子题目类型</label>
		<div class="layui-input-block">
			<select name="type" lay-verify="required" lay-filter="q_type" id="q_type" <{if $topic_info.type|default:"" > 0}> disabled <{/if}>>
				<option value="1" <{if 1 == $topic_info.type|default:""}> selected <{/if}>>单选题</option>
				<option value="2" <{if 2 == $topic_info.type|default:""}> selected <{/if}>>多选题</option>
				<option value="3" <{if 3 == $topic_info.type|default:""}> selected <{/if}>>判断题</option>
				<option value="4" <{if 4 == $topic_info.type|default:""}> selected <{/if}>>简答题</option>
				<option value="5" <{if 5 == $topic_info.type|default:""}> selected <{/if}>>填空题</option>
				<option value="6" <{if 6 == $topic_info.type|default:""}> selected <{/if}>>计算题</option>
			</select>
		</div>
	</div>

	<div class="layui-form-item layui-form-text" id="html_subject_text">
		<label class="layui-form-label">子题目内容<span id="tiankong_tishi" style="color:red; padding-left: 10px;">提示：填空题的题目内容中每4个“_”(例:____，)符作为一个题目答案选项</span></label>
		<div class="layui-input-block">
			<!-- 加载编辑器的容器 -->
		    <script id="container" name="subject_text" type="text/plain">
		        <{$topic_info.subject_text|default:""}>
		    </script>
		    <!-- 配置文件 -->
		    <script type="text/javascript" src="/static/public/ueditor/ueditor.config.js"></script>
		    <!-- 编辑器源码文件 -->
		    <script type="text/javascript" src="/static/public/ueditor/ueditor.all.js"></script>
		    <!-- 实例化编辑器 -->
		    <script type="text/javascript">
		        var ue = UE.getEditor('container');
		    </script>
		</div>
	</div>

	<div class="layui-form-item" id="text_subject_text" style="display: none;">
		<label class="layui-form-label">子题目内容</label>
		<div class="layui-input-block">
			<{if isset($topic_info)}>
				<input type="text" name="subject_text" value="<{$topic_info.subject_text}>" disabled="disabled" autocomplete="off" class="layui-input">
			<{else}>
				<input type="text" name="subject_text" value="" autocomplete="off" class="layui-input" disabled="disabled">
			<{/if}>
		</div>
	</div>
	<{/if}>

	<!--单选答案-->
	<{if $topic_info.type|default:"" == 1 || $t_topic_info.type|default:"" == 1 || (!isset($topic_info) && !isset($t_topic_info))}>
	<div id="an_radio_box">
		<{if isset($topic_result) AND $topic_result|count > 0}>
			<{foreach from=$topic_result key=key item=item}>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">题目答案<{$letter[$key]}></label>
					<div class="layui-input-block">
						<input type="text" name="an_radio_text[1]" value="<{$item.answer_text}>"  lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;" disabled>
					</div>
				</div>

				<div class="layui-inline">
					<input type="radio" name="an_radio" value="1" title="正确答案" <{if $item.is_right == 1}>checked<{/if}> disabled>
				</div>

				<div class="layui-inline">
					<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="<{$item['id']}>" href="javascript:;"><i class="layui-icon"></i></a>
				</div>
			</div>
			<{/foreach}>
		<{else}>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">题目答案A</label>
				<div class="layui-input-block">
					<input type="text" name="an_radio_text[1]"  lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">
				</div>
			</div>

			<div class="layui-inline">
				<input type="radio" name="an_radio" value="1" checked="checked" title="正确答案">
			</div>

			<div class="layui-inline">
				<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="0" href="javascript:;"><i class="layui-icon"></i></a>
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">题目答案B</label>
				<div class="layui-input-block">
					<input type="text" name="an_radio_text[2]"  lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">
				</div>
			</div>
			
			<div class="layui-inline">
				<input type="radio" name="an_radio" value="2" title="正确答案">
			</div>

			<div class="layui-inline">
				<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="0" href="javascript:;"><i class="layui-icon"></i></a>
			</div>
		</div>

		<{/if}>
		<div class="layui-form-item">
			<label class="layui-form-label"></label>
			<a href="javascript:;" class="layui-btn layui-btn-primary add_radio"><i class="layui-icon"></i>新增选项</a>
		</div>
	</div>
	<{/if}>

	<!--多选答案-->
	<{if $topic_info.type|default:"" == 2 || $t_topic_info.type|default:"" == 2}>
	<div id="an_checkbox_box" style="<{if $topic_info.type|default:"" == 2 || $t_topic_info.type|default:"" == 2}>display:block;<{else}>display: none;<{/if}>">
		<{if isset($topic_result) AND $topic_result|count > 0}>
			<{foreach from=$topic_result key=key item=item}>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">题目答案<{$letter[$key]}></label>
					<div class="layui-input-block">
						<input type="text" name="an_checkbox_text[1]" value="<{$item.answer_text}>" lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;" disabled>
					</div>
				</div>
				
				<div class="layui-inline">
					<input type="checkbox" name="an_checkbox[1]" value="1" title="正确答案" <{if $item.is_right == 1}>checked<{/if}> disabled>
				</div>

				<div class="layui-inline">
					<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="<{$item['id']}>" href="javascript:;"><i class="layui-icon"></i></a>
				</div>
			</div>
			<{/foreach}>
		<{else}>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">题目答案A</label>
				<div class="layui-input-block">
					<input type="text" name="an_checkbox_text[1]" lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">
				</div>
			</div>
			
			<div class="layui-inline">
				<input type="checkbox" name="an_checkbox[1]" checked="checked" value="1" title="正确答案">
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">题目答案B</label>
				<div class="layui-input-block">
					<input type="text" name="an_checkbox_text[2]" lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">
				</div>
			</div>
			
			<div class="layui-inline">
				<input type="checkbox" name="an_checkbox[2]" value="1" title="正确答案">
			</div>
		</div>
		<{/if}>
		<div class="layui-form-item">
			<label class="layui-form-label"></label>
			<a href="javascript:;" class="layui-btn layui-btn-primary add_checkbox"><i class="layui-icon"></i>新增选项</a>
		</div>
	</div>
	<{/if}>

	<!--选择题答案-->
	<{if $topic_info.type|default:"" == 3 || $t_topic_info.type|default:"" == 3}>
	<div id="an_choice_box" style='<{if $topic_info.type|default:"" == 3 || $t_topic_info.type|default:"" == 3}>display:block;<{else}>display: none;<{/if}>'>
		<{if isset($topic_result) AND $topic_result|count > 0}>
			<{foreach from=$topic_result key=key item=item}>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">题目答案<{$letter[$key]}></label>
					<div class="layui-input-block">
						<input type="text" name="an_choice_text[1]" lay-verify="title" value="<{$item.answer_text}>" autocomplete="off" class="layui-input" value="对" disabled style="width: 500px;" disabled>
					</div>
				</div>
				
				<div class="layui-inline">
					<input type="radio" name="an_choice" value="1" title="正确答案" <{if $item.is_right == 1}>checked<{/if}> disabled>
				</div>
			</div>
			<{/foreach}>
		<{else}>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">题目答案A</label>
				<div class="layui-input-block">
					<input type="text" name="an_choice_text[1]" lay-verify="required" autocomplete="off" class="layui-input" value="对" disabled style="width: 500px;">
				</div>
			</div>
			
			<div class="layui-inline">
				<input type="radio" name="an_choice" value="1" checked="checked" title="正确答案">
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">题目答案B</label>
				<div class="layui-input-block">
					<input type="text" name="an_choice_text[2]" lay-verify="required" autocomplete="off" class="layui-input" value="错" disabled style="width: 500px;">
				</div>
			</div>
			
			<div class="layui-inline">
				<input type="radio" name="an_choice" value="2" title="正确答案">
			</div>
		</div>
		<{/if}>
	</div>
	<{/if}>

	<{if $topic_info.type|default:"" == 4 || $t_topic_info.type|default:"" == 4}>
	<div id="an_analys_box" style='<{if $topic_info.type|default:"" == 4 || $t_topic_info.type|default:"" == 4}>display:block;<{else}>display: none;<{/if}>'>
		
	</div>
	<{/if}>

	<!--填空题答案-->
	<{if $topic_info.type|default:"" == 5 || $t_topic_info.type|default:"" == 5}>
	<div id="an_tiankong_box" style="<{if $topic_info.type|default:"" == 5 || $t_topic_info.type|default:"" == 5}>display:block;<{else}>display: none;<{/if}>">
		<{if isset($topic_result) AND $topic_result|count > 0}>
			<{foreach from=$topic_result key=key item=item}>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">题目答案<{$letter[$key]}></label>
					<div class="layui-input-block">
						<input type="text" name="an_choice_text[1]" lay-verify="title" value="<{$item.answer_text}>" autocomplete="off" class="layui-input" value="对" disabled style="width: 500px;" disabled>
					</div>
				</div>
			</div>
			<{/foreach}>
		<{else}>
		<div class="layui-form-item">
			<label class="layui-form-label">题目答案1</label>
			<div class="layui-input-block">
				<input type="text" name="an_tiakong[1]" lay-verify="required" autocomplete="off" class="layui-input tiankong_answer">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label"></label>
			<a href="javascript:;" class="layui-btn layui-btn-primary add_tiankong"><i class="layui-icon"></i>新增选项</a>
		</div>
		<{/if}>
	</div>
	<{/if}>

	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">答案解析</label>
		<div class="layui-input-block">
			<textarea class="layui-textarea layui-hide editor" name="analysis" lay-verify="content" id="editor2"><{$topic_info.analysis|default:""}></textarea>
		</div>
	</div>

	<div class="layui-input-block">
		<{if $topic_info.type|default:"" > 2 AND isset($topic_result) AND $topic_result|count > 0}>
			<a class="layui-btn" href="javascript:;" onclick="javascript :history.go(-1)">返回</a>
		<{else}>
		<button class="layui-btn" lay-submit lay-filter="sub_topic">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		<{/if}>
	</div>
</form>


<{include file="public_html/footer.html"}>
<script>
	$(function(){
		$(".sub-colum").find('li').on('click',function(){//子栏目点击选中状态；
			$(this).addClass('curr').siblings().removeClass('curr');
		})
		$("#add_test_volume").click(function(){
			location.href = "/tiku/add_test_volume";
		})

	});

	layui.use(['form', 'jquery', 'layedit', 'element'], function(){
		var layedit = layui.layedit,form = layui.form(),$ = layui.jquery, element = layui.element();

		layui.form().on('select(q_type)', function(data){
			var type = $(data.elem).val();
			$("#html_subject_text").hide();
			$("#text_subject_text").hide();
			$("#html_subject_text").find("textarea").attr("disabled", false);
			$("#text_subject_text").find("input").attr("disabled", false);
			$("#html_subject_text").find("textarea").attr("lay-verify", "");
			$("#text_subject_text").find("input").attr("lay-verify", "");
			if(type == 1){
				$("#html_subject_text").show();
				$("#an_checkbox_box, #an_choice_box, #an_analys_box, #an_tiankong_box").hide();
				$("#an_radio_box").show();
				$("#an_checkbox_box input[type='text']").attr("lay-verify", "");
				$("#an_choice_box input[type='text']").attr("lay-verify", "");
				$("#an_analys_box input[type='text']").attr("lay-verify", "");
				$("#an_tiankong_box input[type='text']").attr("lay-verify", "");
				$("#an_radio_box input[type='text']").attr("lay-verify", "required");
				$("#text_subject_text").find("input").attr("disabled", true);
			}else if(type == 2){
				$("#html_subject_text").show();
				$("#an_radio_box, #an_choice_box, #an_analys_box, #an_tiankong_box").hide();
				$("#an_checkbox_box").show();
				$("#an_radio_box input[type='text']").attr("lay-verify", "");
				$("#an_choice_box input[type='text']").attr("lay-verify", "");
				$("#an_analys_box input[type='text']").attr("lay-verify", "");
				$("#an_tiankong_box input[type='text']").attr("lay-verify", "");
				$("#an_checkbox_box input[type='text']").attr("lay-verify", "required");
				$("#text_subject_text").find("input").attr("disabled", true);
			}else if(type == 3){
				$("#html_subject_text").show();
				$("#an_radio_box, #an_checkbox_box, #an_analys_box, #an_tiankong_box").hide();
				$("#an_choice_box").show();
				$("#an_radio_box input[type='text']").attr("lay-verify", "");
				$("#an_checkbox_box input[type='text']").attr("lay-verify", "");
				$("#an_analys_box input[type='text']").attr("lay-verify", "");
				$("#an_tiankong_box input[type='text']").attr("lay-verify", "");
				$("#an_choice_box input[type='text']").attr("lay-verify", "required");
				$("#text_subject_text").find("input").attr("disabled", true);
			}else if(type == 4){
				$("#html_subject_text").show();
				$("#an_radio_box, #an_checkbox_box, #an_choice_box, #an_analys_box, #an_tiankong_box").hide();
				$("#an_radio_box input[type='text']").attr("lay-verify", "");
				$("#an_checkbox_box input[type='text']").attr("lay-verify", "");
				$("#an_choice_box input[type='text']").attr("lay-verify", "");
				$("#an_analys_box input[type='text']").attr("lay-verify", "");
				$("#an_tiankong_box input[type='text']").attr("lay-verify", "");
				$("#text_subject_text").find("input").attr("disabled", true);
			}/*else if(type == 4){
				$("#html_subject_text").show();
				$("#an_radio_box, #an_checkbox_box, #an_choice_box, #an_tiankong_box").hide();
				$("#an_analys_box").show();
				$("#an_radio_box input[type='text']").attr("lay-verify", "");
				$("#an_checkbox_box input[type='text']").attr("lay-verify", "");
				$("#an_choice_box input[type='text']").attr("lay-verify", "");
				$("#an_tiankong_box input[type='text']").attr("lay-verify", "");
				// $("#an_analys_box input[type='text']").attr("lay-verify", "required");
				$("#text_subject_text").find("input").attr("disabled", true);
			}*/else if(type == 5){
				$("#html_subject_text").show();
				$("#an_radio_box, #an_checkbox_box, #an_choice_box, #an_analys_box").hide();
				$("#an_tiankong_box").show();
				$("#an_radio_box input[type='text']").attr("lay-verify", "");
				$("#an_checkbox_box input[type='text']").attr("lay-verify", "");
				$("#an_choice_box input[type='text']").attr("lay-verify", "");
				$("#an_analys_box input[type='text']").attr("lay-verify", "");
				$("#text_subject_text").find("input").attr("disabled", true);
			}else if(type == 6){
				$("#text_subject_text").show();
				$("#an_radio_box, #an_checkbox_box, #an_choice_box, #an_analys_box, #an_tiankong_box").hide();
				$("#an_radio_box input[type='text']").attr("lay-verify", "");
				$("#an_checkbox_box input[type='text']").attr("lay-verify", "");
				$("#an_choice_box input[type='text']").attr("lay-verify", "");
				$("#an_analys_box input[type='text']").attr("lay-verify", "");
				$("#an_tiankong_box input[type='text']").attr("lay-verify", "");
				$("#html_subject_text").find("textarea").attr("disabled", true);
				$("#text_subject_text").find("input").attr("lay-verify", "required");
			}
		});

		layui.form().on('select(a_type)', function(data){
			var _this = $(data.elem);
			var type = _this.val();
			if(type == 1){
				_this.closest(".layui-tab-item").find(".tk_answer").show();
				_this.closest(".layui-tab-item").find(".fl_answer").hide();
			}else{
				_this.closest(".layui-tab-item").find(".tk_answer").hide();
				_this.closest(".layui-tab-item").find(".fl_answer").show();
			}
		})
		form.on('submit(sub_topic)', function(data){
			var q_type = $("#q_type").val();
			var has_sub_topic = "<{$t_topic_info.has_sub_topic|default:'0'}>";
			if(q_type != 6 && has_sub_topic == 1){
				var subject_text = $.trim(layedit.getContent(edit_editor1));
				if(subject_text == ''){
					layer.msg('请填写题目内容', {icon: 5, anim: 6});
					return false;
				}
				if(q_type == 5){
					var answer_num = (subject_text.split('____')).length-1;
					var answer_text_num = $(".tiankong_answer").length;
					if(answer_text_num < answer_num){
						layer.msg('该题目至少需要' + answer_num + '个答案', {icon: 5, anim: 6});
						return false;
					}
				}
			}

			/*if($("#subject").val() <= 0){
				layer.msg("请选择科目", {icon:5, anim: 6});
				return false;
			}

			if($("#chapter_id").val() <= 0){
				layer.msg("请选择章节", {icon:5, anim: 6});
				return false;
			}

			if($("#category_id").val() <= 0){
				layer.msg("请选择分类", {icon:5, anim: 6});
				return false;
			}

			if($("#area_code").val() <= 0){
				layer.msg("请选择省份", {icon:5, anim: 6});
				return false;
			}*/

			/*layer.alert(JSON.stringify(data.field.type), {
			  title: '最终的提交信息'
			})*/
			if($("#q_type").val() == 2){
				checked_dom = 0;
				$("#an_checkbox_box input[type='checkbox']").each(function (index,domEle){
					if($(domEle).next().hasClass("layui-form-checked")){
						checked_dom += 1;
					}
				});
				if(checked_dom < 2){
					layer.msg('多选题至少需要两个正确答案', {icon: 5, anim: 6});
					return false;
				}
			}
		});

		/**
		 * book_id
		 * @param  {[type]} data){			var ii                                                         [description]
		 * @param  {[type]} success:      function(result){					layer.close(ii);					if(result.code [description]
		 * @return {[type]}               [description]
		 */
		form.on('select(subject)', function(data){
			var ii = layer.load();
			var subject_id = $(data.elem).val();
			$("#book").html('<option value="0">请选择课本</option>');
			form.render('select');
			$.ajax({
				type: "POST",
				url: "/topic/ignore_get_books",
				dataType:"json",
				data:{subject_id:subject_id},
				success: function(result){
					layer.close(ii);
					if(result.code == 1){
						var html ='';
						$.each(result.chapter_list, function(i, obj) {
							$("#book").append('<option value="'+obj.id+'">'+obj.title+'</option>');
						});
						
						form.render('select');
					}
				}
			});
		});

		form.on('select(book)', function(data){
			var ii = layer.load();
			var book_id = $(data.elem).val();
			$("#chapter_id").html('<option value="0">请选择章节</option>');
			form.render('select');
			$.ajax({
				type: "POST",
				url: "/topic/ignore_get_book_chapter",
				dataType:"json",
				data:{book_id:book_id},
				success: function(result){
					layer.close(ii);
					if(result.code == 1){
						var html ='';
						$.each(result.chapter_list, function(i, obj) {
							// html += '<optgroup label="'+ obj.title+'">';
							/*if(obj.sub){
                                $.each(obj.sub, function(j, obj1) {
                                	html += '<option value="'+obj1.id+'">'+obj1.title+'</option>';
                                });
                            }*/
                            html += '<option value="'+obj.id+'">'+obj.title+'</option>';
                            if(obj.sub){
                                $.each(obj.sub, function(j, obj1) {
                                	html += '<option value="'+obj1.id+'">----'+obj1.title+'</option>';
                                });
                            }
                            // html += '</optgroup>'
						});
						$("#chapter_id").append(html);
						form.render('select');
					}
				}
			});
		});

		$(".add_analys").click(function(){
			var _this = $(this);
			var analys_total = _this.closest(".layui-tab-item").find(".fl_answer").length;
			var analys_sx = parseInt(_this.closest(".layui-tab-item").index())+1;
			var html = '<div class="layui-form-item fl_answer">';
			html +=	'<div class="layui-inline">';
			html +=	'<label class="layui-form-label">借贷方向</label>';
			html +=	'<div class="layui-input-block">';
			html += '<select name="analys[type]['+analys_sx+']['+analys_total+']">';
			html +=	'<option value="1" selected>借</option>';
			html +=	'<option value="2">贷</option>';
			html +=	'</select>';
			html +=	'</div>';
			html +=	'</div>';
			html +=	'<div class="layui-inline">';
			html +=	'<label class="layui-form-label">选择科目</label>';
			html +=	'<div class="layui-input-block">';
			html += '<input type="hidden" class="accounts" name="analys[topic_subject_id]['+analys_sx+']['+analys_total+']">';
			html +=	'<input type="text" autocomplete="off" name="analys[topic_subject_title]['+analys_sx+']['+analys_total+']" class="layui-input" readonly onclick="choice_accounts(this)">';
			html +=	'</div>';
			html +=	'</div>';
			html +=	'<div class="layui-inline">';
			html +=	'<label class="layui-form-label">答案</label>';
			html +=	'<div class="layui-input-block">';
			html +=	'<input type="text" name="analys[answer_text]['+analys_sx+']['+analys_total+']"  autocomplete="off" class="layui-input">';
			html +=	'</div>';
			html +=	'</div>';
			html += '<div class="layui-inline">';
			html += 	'<a href="javascript:;" class="layui-btn layui-btn-primary layui-btn-small del_analys" onclick="del_analys(this)"><i class="layui-icon"></i></a>';
			html += '</div>';
			html +='</div>';
			_this.closest(".fl_answer").before(html);
			form.render('select');
		});
/*<div class="layui-form-item">
			<label class="layui-form-label">题目答案1</label>
			<div class="layui-input-block">
				<input type="text" name="an_tiakong[1]" lay-verify="required" autocomplete="off" class="layui-input">
			</div>
		</div>*/
		$(".add_tiankong").click(function(){
			var _this = $(this);
			var tiankong_total = _this.closest("#an_tiankong_box").find(".tiankong_answer").length;
			var index = tiankong_total+1;
			var html = '<div class="layui-form-item">';
			html +=	'<label class="layui-form-label">题目答案' + index +'</label>';
			html +=	'<div class="layui-input-block">';
			html +=	'<input type="text" name="an_tiakong['+index+']" lay-verify="required" autocomplete="off" class="layui-input tiankong_answer">';
			html += '</div></div>';
			_this.closest(".layui-form-item").before(html);
		});

		$(".add_radio").click(function(){
			var _this = $(this);
			var letter = new Array();
			letter = <{$letter|json_encode}>;
			var radio_total = _this.closest("#an_radio_box").find("input[type='radio']").length;
			var index = radio_total+1;
			var html = '<div class="layui-form-item">';
			html +=	'<div class="layui-inline">';
			html +=	'<label class="layui-form-label">题目答案'+letter[index-1]+'</label>';
			html +=	'<div class="layui-input-block">';
			html +=	'<input type="text" name="an_radio_text['+index+']"  lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">';
			html +=	'</div>';
			html +=	'</div>';
			html +=	'<div class="layui-inline">';
			html +=	'<input type="radio" name="an_radio" value="'+index+'" title="正确答案">';
			html +=	'</div>';
			html +=	'<div class="layui-inline">';
			html +=	'<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="0" href="javascript:;"><i class="layui-icon"></i></a>';
			html +=	'</div>';
			html +=	'</div>';
			_this.closest(".layui-form-item").before(html);
			form.render('radio');
		});

		$(".add_checkbox").click(function(){
			var _this = $(this);
			var letter = new Array();
			letter = <{$letter|json_encode}>;
			var checkbox_total = _this.closest("#an_checkbox_box").find("input[type='checkbox']").length;
			var index = checkbox_total+1;
			var html = '<div class="layui-form-item">';
			html +=	'<div class="layui-inline">';
			html +=	'<label class="layui-form-label">题目答案'+letter[index-1]+'</label>';
			html +=	'<div class="layui-input-block">';
			html +=	'<input type="text" name="an_checkbox_text['+index+']" lay-verify="required" autocomplete="off" class="layui-input" style="width: 500px;">';
			html +=	'</div>';
			html +=	'</div>';
				
			html +=	'<div class="layui-inline">';
			html +=	'<input type="checkbox" name="an_checkbox['+index+']" value="1" title="正确答案">';
			html +=	'</div>';
			html +=	'<div class="layui-inline">';
			html +=	'<a class="layui-btn layui-btn-primary layui-btn-small delete_result" resultid="0" href="javascript:;"><i class="layui-icon"></i></a>';
			html +=	'</div>';
			html +=	'</div>';
			_this.closest(".layui-form-item").before(html);
			form.render('checkbox');
		});


	});

	$( document ).on( "click", ".delete_result", function() {

	    var _this = $(this);
		var resultid = _this.attr("resultid");
		var parent = _this.closest(".layui-form-item").parent();
		var total = parent.find(".delete_result").length;
		var id = parent.attr("id");
		if(total <= 2){
			layer.msg("无法删除，因为至少需要两个答案", {icon:5, anim: 5});
			return false;
		}
		if(id == 'an_radio_box'){
			if(_this.closest(".layui-form-item").find("input[type='radio']").is(':checked')){
				layer.msg("无法删除正确答案", {icon:5, anim: 5});
				return false;
			}
		}else if(id == 'an_checkbox_box'){
			checked_dom = 0;
			$("#an_checkbox_box input[type='checkbox']").each(function (index,domEle){
				if($(domEle).next().hasClass("layui-form-checked")){
					checked_dom += 1;
				}
			});
			if(checked_dom <= 2 && _this.closest(".layui-form-item").find("input[type='checkbox']").is(':checked')){
				layer.msg("无法删除，因为至少需要两个正确答案", {icon:5, anim: 5});
				return false;
			}
		}
		if(resultid > 0){
			if(confirm('删除后将无法还原,确定要删除吗?')){
			
			}else{
				return false
			}
			$.ajax({
				type: "POST",
				url: "/topic/ignore_del_topic_result",
				dataType:"json",
				data:{resultid:resultid},
				success: function(result){
					layer.close(ii);
					if(result.error == 1){
						layer.msg(result.msg, {icon:5, anim: 5});
						return false;
					}
					form.render('select');
				}
			});
		}
		_this.closest(".layui-form-item").remove();
  	});

	function del_analys(obj){
		$(obj).closest(".layui-form-item").remove();
	}

	function choice_accounts(obj){
		$(".accounts").attr("id", "");
		$(".accounts").siblings().attr("id", "");
		$(obj).siblings(".accounts").attr("id", "hidden_id");
		$(obj).attr("id", "hidden_id_text");
		layer.open({
			type: 2,
			title: '选择科目',
			shadeClose: true,
			shade: 0.8,
			area: ['20%', '70%'],
			maxmin: true,
			content: '/tk_accounts_subject/iframe_list' //iframe的url
		}); 
	}
</script>